﻿using System;
using UnityEngine;
using UnityEngine.Events;

// Token: 0x02000276 RID: 630
public class LightController : MonoBehaviour
{
	// Token: 0x0600107C RID: 4220 RVA: 0x00068CC8 File Offset: 0x00066EC8
	private void Awake()
	{
		this.sliderPitch.AddOnChangeAction(new UnityAction<float>(this.OnSliderPitch));
		this.sliderYaw.AddOnChangeAction(new UnityAction<float>(this.OnSliderYaw));
		this.sliderPow.AddOnChangeAction(new UnityAction<float>(this.OnSliderPower));
	}

	// Token: 0x0600107D RID: 4221 RVA: 0x00068D1C File Offset: 0x00066F1C
	public void SetupLight()
	{
		Light light = null;
		Light[] array = UnityEngine.Object.FindObjectsOfType<Light>();
		foreach (Light light2 in array)
		{
			if (light2.name.IndexOf("MainLight") == 0)
			{
				light = light2;
				break;
			}
		}
		this.SetupLight(light.transform, true);
	}

	// Token: 0x0600107E RID: 4222 RVA: 0x00068D7C File Offset: 0x00066F7C
	public void SetupLight(Transform mainLight, bool setDef)
	{
		this.invoke = false;
		if (mainLight != null)
		{
			Light[] componentsInChildren = mainLight.GetComponentsInChildren<Light>();
			this.lightSets = new LightController.Set[componentsInChildren.Length];
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				this.lightSets[i] = new LightController.Set(componentsInChildren[i]);
			}
			if (setDef)
			{
				Vector3 eulerAngles = componentsInChildren[0].transform.rotation.eulerAngles;
				this.defYaw = Mathf.DeltaAngle(0f, eulerAngles.y);
				if (this.defYaw > 180f)
				{
					this.defYaw -= 360f;
				}
				this.defPitch = Mathf.DeltaAngle(0f, eulerAngles.x);
				if (this.defPitch > 180f)
				{
					this.defPitch -= 360f;
				}
				this.yaw = this.defYaw;
				this.pitch = this.defPitch;
				this.sliderPitch.SetValue(this.pitch);
				this.sliderYaw.SetValue(this.yaw);
				this.sliderPow.SetValue(this.power);
			}
		}
		this.colorChange.Setup("色", this.color, false, new Action<Color>(this.OnChangeColor));
		if (!setDef)
		{
			this.CalcRotate();
			this.CalcColor();
		}
		this.invoke = true;
	}

	// Token: 0x0600107F RID: 4223 RVA: 0x00068EEC File Offset: 0x000670EC
	private void OnSliderYaw(float val)
	{
		if (!this.invoke)
		{
			return;
		}
		this.yaw = val;
		this.CalcRotate();
	}

	// Token: 0x06001080 RID: 4224 RVA: 0x00068F08 File Offset: 0x00067108
	private void OnSliderPitch(float val)
	{
		if (!this.invoke)
		{
			return;
		}
		this.pitch = val;
		this.CalcRotate();
	}

	// Token: 0x06001081 RID: 4225 RVA: 0x00068F24 File Offset: 0x00067124
	private void OnSliderPower(float val)
	{
		if (!this.invoke)
		{
			return;
		}
		this.power = val;
		this.CalcColor();
	}

	// Token: 0x06001082 RID: 4226 RVA: 0x00068F40 File Offset: 0x00067140
	private void OnChangeColor(Color val)
	{
		if (!this.invoke)
		{
			return;
		}
		this.color = val;
		this.CalcColor();
	}

	// Token: 0x06001083 RID: 4227 RVA: 0x00068F5C File Offset: 0x0006715C
	private void CalcRotate()
	{
		if (this.lightSets.Length > 0)
		{
			this.lightSets[0].light.transform.rotation = Quaternion.Euler(this.pitch, this.yaw, 0f);
		}
	}

	// Token: 0x06001084 RID: 4228 RVA: 0x00068F9C File Offset: 0x0006719C
	private void CalcColor()
	{
		for (int i = 0; i < this.lightSets.Length; i++)
		{
			AlloyAreaLight component = this.lightSets[i].light.GetComponent<AlloyAreaLight>();
			float intensity = this.lightSets[i].defPower * this.power;
			Color color = this.lightSets[i].defColor * this.color;
			component.Intensity = intensity;
			component.Color = color;
			this.lightSets[i].light.intensity = intensity;
			this.lightSets[i].light.color = color;
		}
	}

	// Token: 0x06001085 RID: 4229 RVA: 0x00069038 File Offset: 0x00067238
	public void Reset()
	{
		this.yaw = this.defYaw;
		this.pitch = this.defPitch;
		this.power = 1f;
		this.color = Color.white;
		this.invoke = false;
		this.sliderPitch.SetValue(this.pitch);
		this.sliderYaw.SetValue(this.yaw);
		this.sliderPow.SetValue(this.power);
		this.colorChange.SetColor(this.color);
		this.invoke = true;
		this.CalcRotate();
		this.CalcColor();
		SystemSE.Play(SystemSE.SE.CHOICE);
	}

	// Token: 0x06001086 RID: 4230 RVA: 0x000690D8 File Offset: 0x000672D8
	public void SetDirection(Vector3 euler)
	{
		this.defPitch = Mathf.DeltaAngle(0f, euler.x);
		if (this.defPitch > 180f)
		{
			this.defPitch -= 360f;
		}
		if (this.defPitch > 90f)
		{
			this.defPitch = 180f - this.defPitch;
			euler.y += 180f;
		}
		else if (this.defPitch < -90f)
		{
			this.defPitch = -180f - this.defPitch;
			euler.y += 180f;
		}
		this.defYaw = Mathf.DeltaAngle(0f, euler.y);
		if (this.defYaw > 180f)
		{
			this.defYaw -= 360f;
		}
		this.yaw = this.defYaw;
		this.pitch = this.defPitch;
		this.invoke = false;
		this.sliderPitch.SetValue(this.pitch);
		this.sliderYaw.SetValue(this.yaw);
		this.sliderPow.SetValue(this.power);
		this.invoke = true;
		this.CalcRotate();
	}

	// Token: 0x04001194 RID: 4500
	[SerializeField]
	private InputSliderUI sliderPitch;

	// Token: 0x04001195 RID: 4501
	[SerializeField]
	private InputSliderUI sliderYaw;

	// Token: 0x04001196 RID: 4502
	[SerializeField]
	private InputSliderUI sliderPow;

	// Token: 0x04001197 RID: 4503
	[SerializeField]
	private ColorChangeButton colorChange;

	// Token: 0x04001198 RID: 4504
	private float power = 1f;

	// Token: 0x04001199 RID: 4505
	private Color color = Color.white;

	// Token: 0x0400119A RID: 4506
	private LightController.Set[] lightSets;

	// Token: 0x0400119B RID: 4507
	private bool invoke = true;

	// Token: 0x0400119C RID: 4508
	private float yaw;

	// Token: 0x0400119D RID: 4509
	private float pitch;

	// Token: 0x0400119E RID: 4510
	private float defYaw;

	// Token: 0x0400119F RID: 4511
	private float defPitch;

	// Token: 0x02000277 RID: 631
	private class Set
	{
		// Token: 0x06001087 RID: 4231 RVA: 0x00069228 File Offset: 0x00067428
		public Set(Light light)
		{
			this.light = light;
			this.defPower = light.intensity;
			this.defColor = light.color;
		}

		// Token: 0x040011A0 RID: 4512
		public Light light;

		// Token: 0x040011A1 RID: 4513
		public float defPower;

		// Token: 0x040011A2 RID: 4514
		public Color defColor;
	}
}
